<html>
<head><meta charset="utf-8"><title>pretty print type debug log cycle error · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/pretty.20print.20type.20debug.20log.20cycle.20error.html">pretty print type debug log cycle error</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="163340604"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/pretty%20print%20type%20debug%20log%20cycle%20error/near/163340604" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/pretty.20print.20type.20debug.20log.20cycle.20error.html#163340604">(Apr 14 2019 at 23:35)</a>:</h4>
<p>So, here's a fun thing I stumbled upon..</p>
<p>(I wasn't able to find any existing discussion, issues or PRs about this, I'd not be surprised if someone had found it already, so my bad if this isn't a new problem)</p>
<p>I was about to take a look into <a href="https://github.com/rust-lang/rust/issues/59494" target="_blank" title="https://github.com/rust-lang/rust/issues/59494">#59494</a> (the test case for that will trigger this if you want to follow along at home). I did the first thing I always do, get a backtrace, look at log output and try get a rough idea what is happening where the error/ICE is triggered. But, when I set <code>RUST_LOG=rustc::traits</code>, the error changes - I can see the ICE with just <code>RUST_LOG=rustc::traits::select</code> (IIRC), but not with more than that - I get a cycle error instead.</p>
<p>I guess I'll look into that, I find out it comes from the pretty printer, in particular <a href="https://github.com/rust-lang/rust/blob/master/src/librustc/ty/print/pretty.rs#L547" target="_blank" title="https://github.com/rust-lang/rust/blob/master/src/librustc/ty/print/pretty.rs#L547">this line</a>. Alright, I guess somewhere in that function's call stack, something is doing something it shouldn't and calling <code>predicates_of</code> with the same key.</p>
<p><a href="https://gist.github.com/davidtwco/2ad19e572b568bc3464563c4a13bb208" target="_blank" title="https://gist.github.com/davidtwco/2ad19e572b568bc3464563c4a13bb208">Here's the diff that fixed it</a> (when I was using <code>RUST_LOG=rustc::ty::subst,rustc::ty::context,rustc_typeck</code> which is what I had when I figured this out, I'm sure there are more problematic <code>debug!</code> statements in other modules, like <code>rustc::traits::*</code>). The issue was that the pretty printer calling <code>predicates_of</code> ended up calling code with debug logs that were printing the same type, causing a cycle. I have no idea what to do about this. </p>
<p>Any thoughts? As far as I can tell, there's no easy way for someone modifying <code>rustc_typeck</code> (for example) to know not to print a type in a debug statement because that code is in the path of the pretty printer.</p>



<a name="163373049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/pretty%20print%20type%20debug%20log%20cycle%20error/near/163373049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/pretty.20print.20type.20debug.20log.20cycle.20error.html#163373049">(Apr 15 2019 at 11:55)</a>:</h4>
<p>I filed an issue for this, <a href="https://github.com/rust-lang/rust/issues/59985" target="_blank" title="https://github.com/rust-lang/rust/issues/59985">#59985</a>, so it isn't forgotten about.</p>



<a name="163373128"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/pretty%20print%20type%20debug%20log%20cycle%20error/near/163373128" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/pretty.20print.20type.20debug.20log.20cycle.20error.html#163373128">(Apr 15 2019 at 11:57)</a>:</h4>
<p>We have a test which prints debug stuff, but I only think it's a hello word example</p>



<a name="163373206"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/pretty%20print%20type%20debug%20log%20cycle%20error/near/163373206" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/pretty.20print.20type.20debug.20log.20cycle.20error.html#163373206">(Apr 15 2019 at 11:58)</a>:</h4>
<p>I think this would only happen for existential types, as that was the only type that called <code>predicates_of</code> during printing (IIRC from when I looked last night).</p>



<a name="163374257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/pretty%20print%20type%20debug%20log%20cycle%20error/near/163374257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/pretty.20print.20type.20debug.20log.20cycle.20error.html#163374257">(Apr 15 2019 at 12:18)</a>:</h4>
<p>I’m just not sure how to go about fixing it otherwise I’d have had a PR in.</p>



<a name="163449716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/pretty%20print%20type%20debug%20log%20cycle%20error/near/163449716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/pretty.20print.20type.20debug.20log.20cycle.20error.html#163449716">(Apr 16 2019 at 08:16)</a>:</h4>
<p>Hmm. One way is to generalize the printer to be able to handle cyclic graph structures</p>



<a name="163449730"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/pretty%20print%20type%20debug%20log%20cycle%20error/near/163449730" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/pretty.20print.20type.20debug.20log.20cycle.20error.html#163449730">(Apr 16 2019 at 08:16)</a>:</h4>
<p>But that’s a fair amount of effort</p>



<a name="163449764"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/pretty%20print%20type%20debug%20log%20cycle%20error/near/163449764" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/pretty.20print.20type.20debug.20log.20cycle.20error.html#163449764">(Apr 16 2019 at 08:17)</a>:</h4>
<p>In the short(er) term we could try tracking whether we are currently already executing the pretty printing code and change what we print for existential types in that context</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>